package com.zxp.mylib.main.list

import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.entity.PageModel
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.manager.SDActivityManager
import com.custom.base.mvp.BasePresenterImpl


/**
 * 作者：
 * 时间：2022-03-30
 * 描述：刷新
 */
class ListPresenter : BasePresenterImpl<ListContract.View>(), ListContract.Presenter {
    var list = arrayListOf<ListModel>()
    var adapter: ListAdapter? = null
    var page = PageModel()

    override fun init() {
        mView?.apply {
            adapter = ListAdapter(list, SDActivityManager.instance.lastActivity)
            page.initPullToRefreshListView(listView,adapter)
            page.request(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {

                }
            },object : SDOkHttpResoutCallBack<String>(){
                override fun onSuccess(entity: String) {

                }

                override fun onFinish() {
                    var list2 = arrayListOf<ListModel>()
                    if(page.page < 2){
                        for(i in 1..2){
                            list2.add(ListModel())
                        }
                    }
                    page.updateAdapterByList(list, list2,adapter,0)
                    page.onRefreshComplete()
                }
            })
        }
    }
}